const app = getApp();
Page({
  onGotUserInfo:function(user){
    wx.setStorageSync("user", JSON.parse(user.detail.rawData));
    console.log(user);
    wx.login({
      success: function (res) {
        wx.showToast({
          title: '加载中',
          icon: 'loading',
          duration: 10000
        });
        //发起网络请求  
        wx.request({
          url: app.globalData.BaseURL + '/wx/ma/login',
          data: {
            code: res.code
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          method: 'get',
          success: function (result) {
            wx.hideToast();
            if (result.statusCode == 200) {
              if (result.data.code == 0) {
                var data = result.data.data;
                wx.setStorageSync("userInfo", data);
                var userInfo = wx.getStorageSync('userInfo');
                var token = userInfo.token
                if (token == null) {
                  wx.navigateTo({
                    url: '../profile/profile?openid=' + userInfo.openid,
                  })
                } else {
                  wx.reLaunch({
                    url: '../index/index',
                  })
                }
              } else {
                wx.showToast({
                  title: result.data.message,
                })
              }
            } 
          }
        });
      }
    })
    
  }
})